﻿using System;
using Socium.Domain.Tests;
using Socium.Presentation;

namespace Socium.TestEditor {
	class TestViewModel : FormViewModel<Test> {
		#region Constructors

		public TestViewModel() {}
		public TestViewModel(Test model) : base(model) {}

		#endregion

		#region Name

		string _name;

		public string Name {
			get { return _name; }
			set {
				_name = value;
				OnPropertyChanged("Name");
			}
		}

		#endregion

		#region Description

		string _description;

		public string Description {
			get { return _description; }
			set {
				_description = value;
				OnPropertyChanged("Description");
			}
		}

		#endregion

		protected override void Save(Test model) {
			model.Name = _name;
			model.Description = _description;
		}

		protected override string GetDisplayName(Test model) {
			return model.Name;
		}

		protected override string GetDefaultDisplayName() {
			return "New test";
		}

		protected override Test CreateModel() {
			return new Test(_name);
		}

		protected override void Update(Test model) {
			Name = model.Name;
			Description = model.Description;
		}

		public override bool CanSave() {
			return !string.IsNullOrWhiteSpace(_name);
		}
	}
}
